<!--
จำเป็นต้องมีสำหรับ หน้า print
div => "head" ถูกแสดงด้านบนทุกหน้า
thead => "tableHead" หัวตารางที่จะถูกแสดงทุกหน้า
2 => "" หัวตารางที่จะถูกแสดงทุกหน้า
tr => "row[no]" แถวในตาราง, class => "row"
td => class => "rowTd" ใช้หาความสูงแดวตารางใน IE
tr => "emptyRow" แถวว่างท้ายตาราง
4 => "foot" แสดงที่ส่วนท้ายทุกหน้า
-->
<div id="divFirstHeader"></div>  <div class="header">
    <div class="title">
        <?php echo $this->element('print/title'); ?>
        <table>
            <tr>
                <td width="120px"><label>Vendor</label></td>
                <td><?php echo $this->data['Supplier']['name']; ?></td>
            </tr>
            <?php if ($this->data['CRtSH']['cust_return_status_id'] != CRS::RETURNING) : ?>
                <tr>
                    <td><label>Vendor Document no.</label></td>
                    <td><?php echo!empty($this->data['CRtSH']['vendor_document_no']) ? $this->data['CRtSH']['vendor_document_no'] : '-' ?></td>
                </tr>
            <?php endif; ?>
            </table>
        </div>
        <div class="documentTitle">
            <div class="documentNote">RETURN NOTE</div>
            <table class="documentNo">
                <tr>
                    <td><label>Return no.</label></td>
                    <td><?php echo $this->data['CRtSH']['return_no']; ?></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td width="60px"><label>Return date</label></td>
                    <td width="70px"><?php echo $this->data['CRtSH']['return_date']; ?></td>
                    <td><label>Page</label></td>
                    <td><span class="pageNo">1/1</span></td>
                </tr>
                <tr>
                    <td colspan="2"><label>Status</label></td>
                    <td colspan="2"><?php echo $this->data['CRS']['title']; ?></td>
                </tr>
                <tr>
                    <td colspan="2"><label>Return by</label></td>
                    <td colspan="2"><?php echo $this->data['CRtSH']['return_by']; ?></td>
                </tr>
            </table>
        </div>
        <table class="wide clear">
            <tr>
                <td width="120px"><label>Customer no.</label></td>
                <td width="272px"><?php echo $this->data['Customer']['cust_no']; ?></td>
                <td width="90px"><label>Site no.</label></td>
                <td><?php echo $this->data['Site']['site_no']; ?></td>
            </tr>
            <tr>
                <td><label>Customer name</label></td>
                <td><?php echo $this->data['Customer']['name']; ?></td>
                <td><label>Site name</label></td>
                <td><?php echo $this->data['Site']['name']; ?></td>
            </tr>
        </table>
    </div>

    <div class="main">
        <table id="dataTable" class="dataTable" cellspacing="0" cellpadding="0" >
            <thead id="tableHead">
                <tr align="center">
                    <th width="40px">Item<br>ลำดับ</th>
                    <th width="120px">Part Number<br>รหัสสินค้า</th>
                    <th>Description<br />รายการ</th>
                    <th width="45px">Qty<br />จำนวน</th>
                    <th width="45px">Unit<br />หน่วย</th>
                    <th width="90px">Location<br />ตำแหน่ง</th>
                </tr>
            </thead>
            <tbody id="tableBody">
            <?php $i = 0;
                foreach ($this->data['CRtS'] as $cr) : ?>
            <?php
                    $pl_count = count($cr['ProductLocation']);
                    for ($j = 0; $j < $pl_count; ++$j):
            ?>
                        <tr id="row<?php echo $i; ?>" class="row">
                            <td class="center rowTd"><?php echo $j == 0 ? ($i + 1) : '&nbsp;'; ?></td>
                            <td>
                    <?php echo $cr['Product']['supplier_part_no']; ?><br />
                    <?php echo $cr['CustProductSite']['stock_code']; ?>
                    </td>
                    <td>
                    <?php
                        echo!empty($cr['CustProductSite']['text']) ?
                                $cr['CustProductSite']['text'] :
                                $cr['Product']['text'];
                    ?>
                    </td>
                    <td class="text-right"><?php echo $cr['ProductLocation'][$j]['return_qty']; ?></td>
                    <td class="center"><?php echo $cr['Product']['Unit']['title']; ?></td>
                    <td>
                    <?php
                        echo!empty($cr['ProductLocation'][$j]['CustLocation']['name']) ?
                                $cr['ProductLocation'][$j]['CustLocation']['name'] :
                                'N/A'; // แสดง Location ถ้ามีข้อมูลอยู่?>
                    </td>
                </tr>
            <?php
                        // ถ้ามีแถวที่มี serial no หรือ other information อยู่ (ถ้าไม่มี จะมี แถวว่างมา 1 แถว)
                        $k = 0;
                        foreach ($cr['ProductLocation'][$j]['PS'] as $ps) :
                            if (!empty($ps['ProductSerial']['serial_no']) || !empty($ps['ProductSerial']['other_information'])) :
            ?>
                                <tr class="product_serials_row">
                                    <td>&nbsp;</td>
                                    <td class="rowTd">
                                        <span class="product_serial_no"><?php echo++$k; ?>&nbsp;</span>
                                        <span><?php echo!empty($ps['ProductSerial']['serial_no']) ? $ps['ProductSerial']['serial_no'] : 'N/A' ?></span>
                                    </td>
                                    <td>
                                        <span><?php echo!empty($ps['ProductSerial']['other_information']) ? $ps['ProductSerial']['other_information'] : 'N/A' ?></span>
                                    </td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                    <td>&nbsp;</td>
                                </tr>
            <?php endif;
                            endforeach; ?>
            <?php endfor;
                            ++$i; ?>
            <?php endforeach; ?>
            <?php for ($i = 0; $i < 30; ++$i) : ?>
                                <tr class="emptyRow"> <!-- สร้างแถวเปล่าขึ้นมาเพื่อยืดขนาดตารางให้เต็มหน้า-->
                                    <td class="rowTd">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
                                </tr>
            <?php endfor; ?>
                            </tbody>
                        </table>
                    </div>

                    <div class="footer">
                        <div class="remark" style="width: 270px">
                            <label>Remark</label><br />
        <?php echo $this->data['CRtSH']['remark']; ?>
    </div>
    <table class="right">
        <tr>
            <td>
                <div class="custSignature" style="padding-left: 0px">
                    <hr />
                    <span>Customer Staff/ Date</span>
                </div>
            </td>
            <td>
                <div class="custSignature" style="padding-left: 0px">
                    <hr />
                    <span>Vendor Staff/ Date</span>
                </div>
            </td>
        </tr>
    </table>
</div>
